import type { TransferDataItem } from 'element-plus'
import type { Ref } from 'vue'

/**
 * transfer过滤方法
 * @param query 查询值
 * @param item 当前项
 * @returns
 */
export function transferFilterMethod(query: string, item: TransferDataItem) {
  const label = item.label ?? item.name
  return label.indexOf(query) > -1
}

type IList = {
  name?: string
  id?: string
  [key: string]: any
}[]

/**
 * 设置transfer数据
 * @param source
 * @param list
 */
export function setTransferData(source: Ref<LabelValue[]>, list: IList) {
  source.value = (list ?? []).map(item => {
    return {
      label: item.name!,
      value: item.id!
    }
  })
}
